<template>
	<view class="main">
		<view class="header">
			<view class="header-des">
				<view class="img">
					<image :src="thumb" mode=""></image>
				</view>
				<view class="info">
					<view class="title">
						请选择{{title}} x {{num}}
					</view>
					<view class="tips">在售商品不可参与合成活动</view>
				</view>
			</view>
		</view>
		<view class="content">
			<u-checkbox-group
				placement="column"
				@change="selectSpecialId"
				>
				<view class="item" v-for="(item, index) in list" :key="index">
					<view class="left">
						<view class="code">
							#{{item.goodsCode}}/{{item.allCount}}
						</view>
						<view class="iden">
							链上标识{{item.chain_mark}}
						</view>
					</view>
					<view class="right">
						<view class="price">
							<text>{{ item.price }}</text>
							<text>售价</text>
						</view>
						<u-checkbox activeColor="#000" shape="circle" :name="item.goods_id"></u-checkbox>
					</view>
				</view>
			</u-checkbox>
			</u-checkbox-group>
		</view>
		<view class="ntabar savepadding savebottom" >
			<view class="number">
				<text class="title">已选择：</text>
				<text class="count">{{ selectId.length }} </text>
				<text> 个</text>
			</view>
			<view class="btn">
				<view class="item" :class="{ unchecked:selectId.length!==num }" @click="submit">
					<text>确认选择</text>
					<text>→</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				specialId: '', // 商品id
				id: '',
				title: '', // 需要选择的藏品名称
				num: '', // 需要藏品数量
				pages: 1,
				totals: '',
				purchaselist: [],
				thumb: '',
				selectId: [], // 选中的藏品
				list: [] // 筛选过后的藏品数组
			}
		},
		onLoad(e) {
			this.specialId = e.specialId
			this.id = e.id
			this.title = e.title
			this.num = e.num
		},
		onShow() {
			this.getmylist()
		},
		methods: {
			submit () {
				// if (this.selectId !== this.num) return
				uni.navigateTo({
					url: '/pages/fusion/detail?selectId=' + (this.selectId + '') + '&id=' + this.id
				})
			},
			selectSpecialId (e) {
				this.selectId = e
			},
			// 我拥有的列表
			async getmylist() {
				let data = await this.$http({
					url: this.$api.myShowList,
					method: 'get',
					hideLoading: true,
					data: {
						page: this.pages,
						page_size: 10,
						special_id: this.specialId,
						type: 2,
						sell_status: '1'
					}
				})
				let list = data.data.data
				if (data.code == 200) {
					if (this.pages == 1) {
						this.purchaselist = []
					}
					this.thumb = list[0].thumb
					this.purchaselist = this.purchaselist.concat(list);
					this.totals = data.data.total
					this.list = this.purchaselist.filter(item => item.sell_status !== 1)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.main {
	.header {
		background: #F5F9FF;
		padding: 30rpx;
		&-des {
			display: flex;
			align-items: center;
			.img {
				width: 100rpx;
				height: 100rpx;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.info {
				margin-left: 20rpx;
				.title {
					font-size: 28rpx;
					font-weight: 600;
					color: #16172F;
					margin: 10rpx 0;
				}
				.tips {				
					font-size: 24rpx;	
					color: #8C93AA;
					margin: 10rpx 0;
				}
			}
		}
	}
	.content {
		padding: 30rpx;
		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx;
			border: 1rpx solid #E0E6F0;
			margin: 10rpx 0;
			.left {
				.code {
					font-weight: 600;
					color: #16172F;
					font-size: 28rpx;
				}
				.iden {
					color: #8C93AA;
					font-size: 24rpx;
					margin-top: 10rpx;
				}
			}
			.right { 
				display: flex;
				.price {
					display: flex;
					flex-direction: column;
					margin-right: 20rpx;
					text {
						&:nth-child(1) {
							font-weight: bold;
							color: #16172F;
							font-size: 36rpx;
						}
						&:nth-child(2) {
							color: #8C93AA;
							font-size: 24rpx;
						}
					}
				}
			}
		}
	}
	.ntabar{
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: calc(100% - 54rpx);
		padding: 26rpx 20rpx 26rpx 35rpx;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 1000;
		background-color: #fff;
		.number {
			font-size: 24rpx;
			color: #8C93AA;
			.count {
				font-size: 36rpx;
				font-weight: bold;
				color: #16172F;
			}
		}
		.btn {
			display: flex;
			// justify-content: space-between;
			.item{
				display: flex;
				align-items: center;
				justify-content: space-around;
				width: 268rpx;
				height: 68rpx;
				background: #FFFFFF;
				border-radius: 34rpx;
				border: 1rpx solid #979797;
				font-size: 28rpx;
				color: #16172F;
				&:nth-child(2) {
					margin-left: 10rpx;
				}
			}
			.unchecked {
				color: #949396 !important;
				border: 1rpx solid #949396 !important;
			}
		}
	}
}
</style>
